<?php
/**
 * 用户登录注册控制器
 */
class UserController extends CommonController{
	
	//用户注册
	public function reg(){
		if(IS_POST){
			$Model = K('User');
			if(!$Model->reg()){
				$this->error($Model->error);		
			}
			$this->success('注册成功',__ROOT__.'/index.php/user/login/');
		}
		$this->dis('reg');
	}
	//用户登录
	public function login(){
		if(IS_POST){
			$Model = K('User');
			if(!$Model->login()){
				$this->error($Model->error);		
			}
			$this->success('登录成功',__ROOT__.'/index.php/index/member/');
		}
		$this->dis('login');
	}
	//注销
	public function loginOut(){
		session_unset();
		session_destroy();
		$this->success('注销成功！');
	}
	//验证码
	public function code(){
		$code = new code();
		$code ->show();
	}
	//异步检查用户名是否存在
	public function checkUsername(){
		if(IS_POST){
			$Model = K('user');
			if(!$Model->cheackUsername()){
				$this->error($Model->error);
			}
		}
	}
	//验证码验证
	public function checkCode(){
		if(IS_POST){
			$Model = K('user');
			if(!$Model->cheackCode()){
				$this->error($Model->error);
			}
		}
	}
}
